package Vistas;

import java.awt.EventQueue;
import java.awt.RenderingHints.Key;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.sql.Date;
import java.util.Calendar;
import java.util.Vector;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;

import org.jvnet.substance.SubstanceLookAndFeel;

import Procesos.CargarDatos;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTable;
import javax.swing.JComboBox;
import javax.swing.JScrollPane;

import com.toedter.calendar.JCalendar;
import com.toedter.calendar.JDayChooser;
import com.toedter.calendar.JDateChooser;

public class Faltas extends JInternalFrame implements PropertyChangeListener, ActionListener {

	private JPanel contentPane;
	private DefaultTableModel modelo;
	private JButton btnGuardar;
	private JDateChooser dateChooser;
	private JComboBox comboBox = new JComboBox();
	private JComboBox comboBox_1 = new JComboBox();
	private CargarDatos cargaCurso = new CargarDatos();
	private CargarDatos cargaAlumnos = new CargarDatos();
	private Calendar calendario;
	private CargarDatos cabecera = new CargarDatos();
	private Object[][] datos ={{""}};
	protected String[] cursos = {"Desarrollo de Aplicaciones Multiplataforma","Administracion de Sistemas Informaticos en Red","Sistemas Microinformaticos y Redes"};
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JFrame.setDefaultLookAndFeelDecorated(true);
					SubstanceLookAndFeel.setSkin("org.jvnet.substance.skin.BusinessBlackSteelSkin");
					Faltas frame = new Faltas();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Faltas() {
		setTitle("Faltas");
		setClosable(true);
		setMaximizable(true);
		setBounds(100, 100, 684, 329);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JPanel panel = new JPanel();
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addGap(67))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.TRAILING)
				.addGroup(Alignment.LEADING, gl_contentPane.createSequentialGroup()
					.addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
					.addContainerGap())
		);
		
		JLabel lblCurso = new JLabel("Curso:");
		
		modelo = new DefaultTableModel();
		
		
		comboBox = new JComboBox(cursos);
		comboBox.addPropertyChangeListener(this);
		
		JLabel lblDia = new JLabel("Dia:");
		
		JLabel lblHora = new JLabel("Hora:");
		
		dateChooser = new JDateChooser();
		calendario = dateChooser.getCalendar();
		
		JScrollPane scrollPane = new JScrollPane();
		
		JButton btnMostrarLista = new JButton("Mostrar Lista");
		btnMostrarLista.setName("Mostrar");
		btnMostrarLista.addActionListener( this);
		
		
		btnGuardar = new JButton("Guardar");
		btnGuardar.setName("Guardar");
		btnGuardar.addActionListener(this);
		
		
		GroupLayout gl_panel = new GroupLayout(panel);
		gl_panel.setHorizontalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(Alignment.TRAILING, gl_panel.createSequentialGroup()
							.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 512, Short.MAX_VALUE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(btnGuardar)
							.addGap(4))
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(lblCurso)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(comboBox, 0, 301, Short.MAX_VALUE)
							.addPreferredGap(ComponentPlacement.UNRELATED)
							.addComponent(lblDia)
							.addGap(2)
							.addComponent(dateChooser, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(lblHora)
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(btnMostrarLista)))
					.addContainerGap())
		);
		gl_panel.setVerticalGroup(
			gl_panel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_panel.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
							.addComponent(lblCurso)
							.addComponent(comboBox, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE))
						.addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
							.addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblDia)
								.addComponent(lblHora)
								.addComponent(btnMostrarLista))
							.addComponent(dateChooser, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(btnGuardar)
							.addGap(70))
						.addGroup(gl_panel.createSequentialGroup()
							.addComponent(scrollPane, GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
							.addContainerGap())))
		);
		
		table = new JTable(datos, cabecera.getCabecera());
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{""}
			},
			new String[] {
				"Nombre", "Apellidos", "Falta", "Retraso"
			}
		) {
			Class[] columnTypes = new Class[] {
				String.class, String.class, Boolean.class, Boolean.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});
		
		scrollPane.setViewportView(table);
		panel.setLayout(gl_panel);
		contentPane.setLayout(gl_contentPane);
	}

	@Override
	public void propertyChange(PropertyChangeEvent evt){ 
	
		
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if(e.getSource() instanceof JButton){
			JButton boton = (JButton)e.getSource();
			if(boton.getName().equals("Mostrar")){
				if(comboBox.getSelectedItem().toString().equals(cursos[0].toString())){
					Object[][]alumno = cargaAlumnos.cargarDatosAlumnos(cursos[0].toString());
					table.setModel(new DefaultTableModel(alumno, cabecera.getCabecera()) {
						Class[] columnTypes = new Class[] {
								String.class, String.class, Boolean.class, Boolean.class
							};
							public Class getColumnClass(int columnIndex) {
								return columnTypes[columnIndex];
							}
						});
				}
				if(comboBox.getSelectedItem().toString().equals(cursos[1].toString())){
					Object[][] alumno = cargaAlumnos.cargarDatosAlumnos(cursos[1].toString());
					table.setModel(new DefaultTableModel(alumno, cabecera.getCabecera())
					 {
						Class[] columnTypes = new Class[] {
							String.class, String.class, Boolean.class, Boolean.class
						};
						public Class getColumnClass(int columnIndex) {
							return columnTypes[columnIndex];
						}
					});
				}
				if(comboBox.getSelectedItem().toString().equals(cursos[2].toString())){
					Object[][]alumno = cargaAlumnos.cargarDatosAlumnos(cursos[2].toString());
					table.setModel(new DefaultTableModel(alumno, cabecera.getCabecera()) {
						Class[] columnTypes = new Class[] {
								String.class, String.class, Boolean.class, Boolean.class
							};
							public Class getColumnClass(int columnIndex) {
								return columnTypes[columnIndex];
							}
						});
					}
			}else{
				this.dispose();
			}
		}
		
	}		
}


